#!/bin/bash
deleteSUID()
{
    find / -perm -4000 1>file_SUID 2>/dev/null
    for i in `cat file_SUID`
    do
       echo "$count: $i"
       shuzu1[$count-1]=$i
       let count=$count+1
    done
    echo ""
    echo "Please enter the number that you want to delete:"
    read -a shuzu2
    for j in ${shuzu2[*]}
      do
        let temp=$j-1
        chmod u-s ${shuzu1[$temp]}
        echo "${shuzu1[$temp]} have been processed"
        echo "${shuzu1[$temp]}">>deleted_SUID
      done  
}
deleteSGID()
{
   find / -perm -2000 1>file_SGID 2>/dev/null
    for i in `cat file_SGID`
    do
       echo "$count: $i"
       shuzu1[$count-1]=$i
       let count=$count+1
    done
    echo ""
    echo "Please enter the number that you want to delete:"
    read -a shuzu2
    for j in ${shuzu2[*]}
      do
        let temp=$j-1
        chmod g-s ${shuzu1[$temp]}
        echo "${shuzu1[$temp]} have been processed"
        echo "${shuzu1[$temp]}">>deleted_SGID
      done  
}
recoverSUID()
{
    for i in `cat deleted_SUID`
    do
       echo "$count: $i"
       shuzu1[$count-1]=$i
       let count=$count+1
    done
    echo ""
    echo "Please enter the number that you want to recover:"
    read -a shuzu2
    for j in ${shuzu2[*]}
      do
        let temp=$j-1
        chmod u+s ${shuzu1[$temp]}
        echo "${shuzu1[$temp]} have been processed"
      done  
}
recoverSGID()
{
   for i in `cat deleted_SGID`
    do
       echo "$count: $i"
       shuzu1[$count-1]=$i
       let count=$count+1
    done
    echo ""
    echo "Please enter the number that you want to recover:"
    read -a shuzu2
    for j in ${shuzu2[*]}
      do
        let temp=$j-1
        chmod g+s ${shuzu1[$temp]}
       $ sed '/'"${shuzu1[$temp]}"'/d' deleted_SGID
        echo "${shuzu1[$temp]} have been processed"
      done  
}
while [ 1 ]
do
clear
count=1
echo "***********************************************"
echo "                 Welcome"
echo "      SUID and SGID delete and recover"
echo "***********************************************"
echo "1.delete SUID"
echo "2.delete SGID"
echo "3.recover SUID"
echo "4.recover SGID"
echo "5.exit "
echo ""
echo "Please choose the number"
read choose
if [ $choose -eq 1 ]
  then
      deleteSUID
elif [ $choose -eq 2 ]
  then
      deleteSGID
elif [ $choose -eq 3 ]
   then
       recoverSUID
elif [ $choose -eq 4 ]
   then
       recoverSGID
elif [ $choose -eq 5 ]
   then
       exit
else
    echo "Input error!!"
fi
done
 
    
